/*******************************************************************
** This code is part of Breakout.
**
** Breakout is free software: you can redistribute it and/or modify
** it under the terms of the CC BY 4.0 license as published by
** Creative Commons, either version 4 of the License, or (at your
** option) any later version.
******************************************************************/
#ifndef GAMEOBJECT_H
#define GAMEOBJECT_H

#include <glad/glad.h>
#include <glm_no_warnings.h>
#include <box2d/box2d.h>

#include "texture.h"
#include "spriterenderer.h"


// Container object for holding all state relevant for a single
// game object entity. Each object in the game likely needs the
// minimal of state as described within GameObject.
class GameObject
{
public:
	int mTag;
    // 空的构造函数 后续会添加set_xxx()的method以设置成员
    GameObject();
    // 根据位置信息初始化目标并创建对应的刚体
    GameObject(b2World *world, glm::vec2 pos, glm::vec2 size, Texture2D sprite, glm::vec3 color = glm::vec3(1.0f));
    // Draw sprite
    virtual void Draw(SpriteRenderer &renderer);

	glm::vec2 b2vec2toglmvec2(const b2Vec2& vec);

	inline b2Body *getPhysicBody() const { return mPhysicBody; }
	inline glm::vec3 getColor() const { return mColor; }
	inline glm::vec2 getSize() const { return mSize; }
	inline GLboolean isSolid() const { return mIsSolid; }
	inline GLboolean isDestroyed() const { return mDestroyed; }
	inline int getTag() const {return mTag;}

	inline void setAsDestroyed(GLboolean newstate = true) { mDestroyed = newstate; }
	inline void setAsSolid(GLboolean newstate = true) { mIsSolid = newstate; }
	inline void setTag(int newtag){mTag = newtag;}

protected:
	// Object state
	b2Body      *mPhysicBody;
	glm::vec3   mColor;
	GLboolean   mIsSolid;
	GLboolean   mDestroyed;
	// Render state
	Texture2D   mSprite;
	glm::vec2  mSize;

};

#endif